Test Series - Data Structure

Test Number 5/115

Q: The postfix form of the expression (A+ B)*(C*D- E)*F / G is?
A. AB+ CD*E – FG /**
B. AB + CD* E – F **G /
C. AB + CD* E – *F *G /
D. AB + CDE * – * F *G /
Solution: (((A+ B)*(C*D- E)*F) / G) is converted to postfix expression as
(AB+(*(C*D- E)*F )/ G)
(AB+CD*E-*F) / G
(AB+CD*E-*F * G/). Thus Postfix expression is AB+CD*E-*F*G/
Q:  The data structure required to check whether an expression contains a balanced parenthesis is?
A. Stack
B. Queue
C. Array
D. Tree
Solution: The stack is a simple data structure in which elements are added and removed based on the LIFO principle. Open parenthesis is pushed into the stack and a closed parenthesis pops out elements till the top element of the stack is its corresponding open parenthesis. If the stack is empty, parenthesis is balanced otherwise it is unbalanced.
Q: What data structure would you mostly likely see in non recursive implementation of a recursive algorithm?
A. Linked List
B. Stack
C. Queue
D. Tree
Solution: In recursive algorithms, the order in which the recursive process comes back is the reverse of the order in which it goes forward during execution. The compiler uses the stack data structure to implement recursion. In the forwarding phase, the values of local variables, parameters and the return address are pushed into the stack at each recursion level. In the backing-out phase, the stacked address is popped and used to execute the rest of the code.
Q: The process of accessing data stored in a serial access memory is similar to manipulating data on a ________
A. Heap
B. Binary Tree
C. Array
D. Stack
Solution: In serial access memory data records are stored one after the other in which they are created and are accessed sequentially. In stack data structure, elements are accessed sequentially. Stack data structure resembles the serial access memory.
Q: The postfix form of A*B+C/D is?
A. *AB/CD+
B. AB*CD/+
C. A*BC+/D
D. ABCD+/*
Solution: Infix expression is (A*B)+(C/D)
AB*+(C/D)
AB*CD/+. Thus postfix expression is AB*CD/+.
Q: Which data structure is needed to convert infix notation to postfix notation?
A. Branch
B. Tree
C. Queue
D. Stack
Solution: The Stack data structure is used to convert infix expression to postfix expression. The purpose of stack is to reverse the order of the operators in the expression. It also serves as a storage structure, as no operator can be printed until both of its operands have appeared.
Q: The prefix form of A-B/ (C * D ^ E) is?
A. -/*^ACBDE
B. -ABCD*^DE
C. -A/B*C^DE
D. -A/BC*^DE
Solution: Infix Expression is (A-B)/(C*D^E)
(-A/B)(C*D^E)
-A/B*C^DE. Thus prefix expression is -A/B*C^DE.
Q: What is the result of the following operation?
Top (Push (S, X))
A. X
B. X+S
C. S
D. XS
Solution: The function Push(S,X) pushes the value X in the stack S. Top() function gives the value which entered last. X entered into stack S at last.
Q: The prefix form of an infix expression (p + q) – (r * t) is?
A. + pq – *rt
B. – +pqr * t
C. – +pq * rt
D. – + * pqrt
Solution: Explanation: Given Infix Expression is ((p+q)-(r*t))
(+pq)-(r*t)
(-+pq)(r*t)
-+pq*rt. Thus prefix expression is -+pq*rt.
Q: Which data structure is used for implementing recursion?
A. Queue
B. Stack
C. Array
D. List
Solution: Stacks are used for the implementation of Recursion.

You Have Score    /10